<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use App\Model\Users;

class RegisterController extends Controller
{
	use RegistersUsers;
    protected $redirectTo = '/Admin/login'; //成功后跳转

    // public function __construct()
    // {
    //     $this->middleware('guest');
    // }

    //自定义获取视图地址
    public function showRegistrationForm()
    {
        return view('auth.register');
    }

    //数据验证 
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'username' => 'required|string|max:12',
            'nick' => 'required|string|max:12',
            'email' => 'required|string|email|max:30|unique:users',
            'password' => 'required|string|min:5|confirmed',
        ]);
    }

    //开始插入数据
    protected function create(array $data)
    {
        return Users::create([
            'username' => $data['username'],
            'nick' => $data['nick'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}
